/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package component.xml;

import controller.MyController;
import database.operate.OperateMyDatabaseImpl;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import javafx.scene.control.TreeItem;
import myfx.jfxpanel.MyTreeContainer;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 *
 * @author Administrator
 */
public class XMLLoader {
    private String filepath=java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("");
    private MyTreeContainer treeContainer;
    private MyController controller;
    public XMLLoader(String filepath,myfx.jfxpanel.MyTreeContainer treeContainer,MyController controller){
        this.treeContainer=treeContainer;
        this.filepath=filepath;
        this.controller=controller;
    }
    
    public void doLoad() throws DocumentException, Exception{
        SAXReader reader=new SAXReader();
        Document document=reader.read(new File(filepath));
        Element root=document.getRootElement();
        Iterator<Element> gzmIt=root.elementIterator(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("工作面"));
        
        TreeItem<String> rootItem=treeContainer.getTree().getRoot();
        
        while(gzmIt.hasNext()){
            Element gzmElement=gzmIt.next();
            List<Attribute> gzmAttrList=gzmElement.attributes();
            OperateMyDatabaseImpl.doAdd
                    (java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("INSERT INTO GONGZUOMIAN VALUES(")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")+gzmAttrList.get(0).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(1).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(2).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(3).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(4).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(5).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(6).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(7).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(8).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(9).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(10).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(11).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(12).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+gzmAttrList.get(13).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                    + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(");"));
            TreeItem<String> gzmItem=new TreeItem<String>(gzmAttrList.get(0).getStringValue());
            rootItem.getChildren().add(gzmItem);
            Iterator<Element> zcIt=gzmElement.elementIterator(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("钻场"));
            while(zcIt.hasNext()){
                Element zcElement=zcIt.next();
                List<Attribute> zcAttrList=zcElement.attributes();
                OperateMyDatabaseImpl.doAdd
                        (java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("INSERT INTO ZUANCHANG VALUES(")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")+zcAttrList.get(0).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(1).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(2).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(3).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(4).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(5).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(6).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zcAttrList.get(7).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")                    
                        + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(");"));
                TreeItem<String> zcItem=new TreeItem<String>(zcAttrList.get(0).getStringValue());
                gzmItem.getChildren().add(zcItem);
                Iterator<Element> zkIt=zcElement.elementIterator(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("钻孔"));
                while(zkIt.hasNext()){
                    Element zkElement=zkIt.next();
                    List<Attribute> zkAttrList=zkElement.attributes();
                    OperateMyDatabaseImpl.doAdd
                            (java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("INSERT INTO ZUANKONG VALUES(")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")+zkAttrList.get(0).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(1).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(2).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(3).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(4).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(5).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(6).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(7).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")   
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(8).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(9).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(10).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(11).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(12).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(13).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(14).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")  
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(15).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(16).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(17).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(18).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(19).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(20).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(21).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")  
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(",'")+zkAttrList.get(22).getStringValue()+java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("'")
                            + java.util.ResourceBundle.getBundle("myproj/globalizefile").getString(");"));
                    TreeItem<String> zkItem=new TreeItem<String>(zkAttrList.get(0).getStringValue());
                    zcItem.getChildren().add(zkItem);
                }
            }
        }
        controller.getFxStatus().updateStatus(java.util.ResourceBundle.getBundle("myproj/globalizefile").getString("导入数据完成"), this.getClass().toString(), this.getFilepath(), this.getFilepath());
    }
    
    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath;
    }
}
